import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.border.LineBorder;


public class RailroadLot extends Lot
{
	private int price;
	private int rent1Railroad;
	private int rent2Railroads;
	private int rent3Railroads;
	private int rent4Railroads;
	private int mortgageValue;
	private int ownedBy;		// determines which players owns the property
								// 0 - no owner, 1 - P1 owns, 2 - P2 owns, etc.
	// Dimensions:
	private int WIDTH;			// width of the property graphic
	private int HEIGHT;			// height of the property graphic
	
//	private ImageIcon imageReading; // image used for the Reading logo on the lot
//	private ImageIcon imagePennsylvania; // image used for the Pennsylvania logo on the lot
//	private ImageIcon imageBandO; // image used for the B&O logo on the lot
//	private ImageIcon imageShortLine; // image used for the ShortLine logo on the lot
	private ImageIcon logo; // image used for logo on the lot

	private PropertyCardPanel pcp;
//	private boolean mouseFlag;
	
	
	public RailroadLot(String name, String type, String location)
	{
		super(name, type, location);
		
		price = 200;
		rent1Railroad = 25;
		rent2Railroads = 50;
		rent3Railroads = 100;
		rent4Railroads = 200;
		mortgageValue = 100;
		ownedBy = 0; // initially no one owns it
//		mouseFlag = false;
		
		if(location == "north" || location == "south")
		{
			WIDTH = 55;
			HEIGHT = 100;
		}
		else if(location == "east" || location == "west")
		{
			WIDTH = 100;
			HEIGHT = 55;
		}

		// sets the logo on the property on the game board
		setLogo();

		addMouseListener(new RailroadListener());
		pcp = new PropertyCardPanel();
		pcp.changeImage(name + ".jpg");
		pcp.setCostLabel(price);
		
		
		setPreferredSize(new Dimension(WIDTH, HEIGHT));
		setBorder(new LineBorder(Color.black));
		setBackground(new Color(200,222,186));
		
	} // end RailroadLot constructor
	
	public void setLogo()
	{
		// Creates a new ImageIcon from the name (String) of the property selected
		// and repaints??
		logo = new ImageIcon("./logos/" + name + "_small.jpg");		
		//repaint(); // not needed???
	}
	
	public int getPrice()
	{
		return price;
	} // end getPrice	
	
	public int getRent1Railroad()
	{
		return rent1Railroad;
	} // end getRentValue
	
	public int getRent2Railroads()
	{
		return rent2Railroads;
	} // end getRent3Railroads
	
	public int getRent3Railroads()
	{
		return rent3Railroads;
	} // end getRent3Railroads

	public int getRent4Railroads()
	{
		return rent4Railroads;
	} // end getRent4Railroads
	
	public int getMortgageValue()
	{
		return mortgageValue;
	} // end getMortgageValue
	
	public int getOwnedStatus()
	{
		return ownedBy;
	} // end getOwnedStatus

	// will actually draw the image:
	public void paintComponent(Graphics g)
	{	
		super.paintComponent(g);
		g.setColor(new Color(200,222,186));
		g.fillRect(0, 0, 55, 100);
		
		// draw black lines to make property borders thicker looking
		g.setColor(Color.black);
		
		if(location == "south")		
		{
			g.drawLine(1, 1, 55, 1);
			logo.paintIcon(this, g, 1, 2);
		}
		else if(location == "north")
		{
			g.drawLine(1, 98, 55, 98);
			logo.paintIcon(this, g, 2, 0);
		}
		else if(location == "east")
		{
			g.drawLine(1, 1, 1, 55);
			logo.paintIcon(this, g, 2, 1);
		}
			else if(location == "west")
		{
			g.drawLine(98, 0, 98, 55);
			logo.paintIcon(this, g, 0, 1);;
		}			
	} // end paintComponent
	
	private class RailroadListener implements MouseListener
	{
		public void mouseClicked(MouseEvent event)
		{			
			// open a frame with the PropertyCardPanel
			JFrame frame = new JFrame ("Railroad Card");
			
			frame.setDefaultCloseOperation (JFrame.DISPOSE_ON_CLOSE);
			
			// add the PropertyCardPanel to the frame
			frame.getContentPane().add(pcp);
			frame.pack();
			frame.setLocationRelativeTo(null);
			frame.setResizable(true);
			frame.setVisible(true);			
		}
		
		public void mousePressed(MouseEvent event){}
		public void mouseReleased(MouseEvent event){}
		public void mouseEntered(MouseEvent event)
		{
//			mouseFlag = true;
//			repaint();
		}
		public void mouseExited(MouseEvent event)
		{
//			mouseFlag = false;
//			repaint();
		}		
	} // end class UtilityListener
	
} // end class RailroadLot